package com.kun.companion.core.queue.ui.button;

import com.kun.companion.core.context.ContextService;
import com.kun.companion.core.queue.EventMessageQueue;
import com.kun.companion.core.queue.ButtonEvent;
import com.kun.companion.core.ui.button.AbstractButton;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Node;

import java.util.concurrent.CompletableFuture;

/**
 * 同步事件按钮，点击按钮后按钮会变成禁用状态并且有加载中的动态效果，等待事件执行完毕后更新按钮为可用状态并且移除加载中的动态效果。
 *
 * @author gzc
 * @since 2025/2/5
 **/
public abstract class EventButton extends AbstractButton {
    private final EventMessageQueue eventMessageQueue;

    public EventButton(String buttonText) {
        this(buttonText, null, "");
    }

    public EventButton(String buttonText, Node svgGraphic, String tipText) {
        super(buttonText, svgGraphic, tipText);
        eventMessageQueue = ContextService.getBean(EventMessageQueue.class);
    }

    @Override
    protected CompletableFuture<Void> doHandleAction(ButtonEvent event,
                                                     Runnable successCallback,
                                                     Runnable failureCallback) {
        return eventMessageQueue.submitEvent(event, successCallback, failureCallback);
    }

}
